/*Part of the CEFIRO project by dyrtech.com.ve. Copyleft GPLv3 2007. Please see the disclaimer at the root of the project: http://dyrtech.com.ve/cefiro/license.txt*/
function Blend() {
  this.fadeTime = 300;
  this.fadeOpac = 99;
  this.fadeTrsp = 0;
  this.blendobj = null;
  this.blendprop = null;
  this.blenddata = null;

  this.opacity = function(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
      for(i = opacStart; i >= opacEnd; i--) {
        setTimeout("blend.changeOpac(" + i + ",'" + id + "')",(timer * speed));
        timer++;
      }
    } else if(opacStart < opacEnd) {
      for(i = opacStart; i <= opacEnd; i++) {
        setTimeout("blend.changeOpac(" + i + ",'" + id + "')",(timer * speed));
        timer++;
      }
    }
  }

  // change an element's opacity when appearing or hiding
  this.changeOpac = function (opacity, id) {
    var object = zajax.$(id,'style');
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
  }

  this.shiftOpacity = function (id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(zajax.$(id,'style').opacity == 0)
      this.opacity(id, 0, 100, millisec);
    else
      this.opacity(id, 100, 0, millisec);
  }

  this.blendimage = function(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //set the current image as background
    zajax.$(divid).style.backgroundImage = "url(" + zajax.$(imageid,'src') + ")";
    //make image transparent
    this.changeOpac(0, imageid);
    //make new image
    zajax.$(imageid).src = imagefile;
    //fade in image
    for(i = 0; i <= 100; i++) {
      setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
      timer++;
    }
  }

  this.currentOpac = function(id, opacEnd, millisec) {
    //standard opacity is 100
    var currentOpac = 100;

    //if the element has an opacity set, get it
    if(zajax.$(id,'style').opacity < 100)
      currentOpac = zajax.$(id,'style').opacity * 100;
    //call for the function that changes the opacity
    this.opacity(id, currentOpac, opacEnd, millisec)
  }

  this.initZajaxR = function(obj,prop,dat){
    this.blendobj = obj;
    this.blendprop = prop;
    this.blenddata = dat;
  }

  this.doZajaxR = function(){
    eval("this.blendobj."+this.blendprop+"=this.blenddata;");
  }

  this.changeValues = function(fadeT,fadeO,fadeA){
    this.fadeTime = fadeT;
    this.fadeOpac = fadeO;
    this.fadeTrsp = fadeA;
  }
}

function Zajax()
{
  // Attributes:
  this.document = document;
  this.root = this.document;
  this.depth = 0;
  this.zajaxDebug = true;
  var loadingTimeout;

  this.loadingFunction = function(){};
  this.doneLoadingFunction = function(){};

  // Advanced management of pahts :)
  this.webPath = '../../web/';
  this.webUri = document.location.href.substring(0, document.location.href.lastIndexOf('/web/')) + '/web/';
  this.js = document.getElementById('zajaxid').src;
  this.zUri = this.js.substring(0,this.js.lastIndexOf('/')) + '/';
  this.php = this.zUri + 'zajax.php';

  // Utility functions:

  // Codifica las cadenas mediante encodeUriComponent
  // ademas cambia s'imbolos que no acepte la libreria simpleXML
  this.encodeStr = function(sString){
    sString = sString.replace(/\+/g,'ZAJAXPLUS');
    return encodeURIComponent(sString);
  }

  // Asigna el ambito de trabajo de zajax a un marco,
  // usando su nombre o el objeto -self- como comodin
  // si no se coloca nada, vuelve al documento padre.
  this.setDocument = function(s){
    if (s){
      var documentName = '';
      if(s.name)
        documentName = s.name;
      else
        documentName = s;
      if(documentName != ''){
        eval("this.document = self."+documentName+".document;");
        return;
      }
    }
    this.document = this.root;
  }

  // Allows the output of zajax errors thorough firebug's console
  this.debug = function(e){
    if (this.zajaxDebug && typeof(console) == 'object') {
      if (typeof(e)=="object")
        console.debug(e.name+": "+e.message);
      else if (typeof(e)=="string")
        console.debug(e);
    }
  }

  // zajax.$(sId) is shorthand for document.getElementById(sId)
  // zajax.$(sId,'sProp') now also GETS zajax.$(sId).sProp
  // zajax.$(sId,'text') and is a combo returns its selected text
  this.$ = function(sId,sProp)
  {
    if (!sId)
      return null;
    returnObj = this.document.getElementById(sId);
    if (!returnObj && this.document.all)
      returnObj = this.document.all[sId];
    if (!returnObj)
      this.debug("Elemento con el id \"" + sId + "\" no encontrado.");
    if (sProp && returnObj){
      if (sProp == 'text' && returnObj.selectedIndex != null)
        return returnObj[returnObj.selectedIndex].text;
      if (returnObj[sProp] != null)
        return returnObj[sProp];
    }
    return returnObj;
  }

  // zajax.include(sFileName) dynamically includes an external javascript file
  this.include = function(sFileName)
  {
    //first search for the script, and if it exists, delete it.
    var aScripts = this.document.getElementsByTagName('script');
    for (i = 0 ; i < aScripts.length ; i++)
      if (aScripts[i].src == sFileName)
        aScripts[i].parentNode.removeChild(aScripts[i]);
    var objHead = this.document.getElementsByTagName('head');
    var objScript = this.document.createElement('script');
    objScript.type = 'text/javascript';
    objScript.src = sFileName;
    objHead[0].appendChild(objScript);
  }

  // zajax.includeCss(sFileName) dynamically includes an external css file
  this.includeCss = function(sFileName)
  {
    //first search for the cascade style sheet, and if it exists, delete it.
    var aCss = this.document.getElementsByTagName('link');
    for (i = 0 ; i < aCss.length ; i++)
      if (aCss[i].href == sFileName)
        aCss[i].parentNode.removeChild(aCss[i]);
    var objHead = this.document.getElementsByTagName('head');
    var objCss = this.document.createElement('link');
    objCss.type = 'text/css';
    objCss.rel = 'stylesheet';
    objCss.href = sFileName;
    objHead[0].appendChild(objCss);
  }

  // Functions:

  // zajax.getFormValues() builds a query string XML message from the elements of a form object
  // * The first argument is the id of the form
  // * The second argument (LeoZ) is additional params you wish to submit
  // * (optional) can be set to true if you want to submit disabled elements
  // * The third argument (optional) allows you to specify a string prefix that a form element
  //   name must contain if you want that element to be submitted
  this.getFormValues = function(frm) {
    arr = new Array();
    var objForm;
    var submitDisabledElements = true;
    var prefix="";

    if(arguments.length > 2)
      prefix = arguments[2];

    if (typeof(frm) == "string")
      objForm = this.$(frm);
    else
      objForm = frm;

    if (arguments.length > 1)
      for (prop in arguments[1])
        arr[prop] = arguments[1][prop];

    if (objForm && objForm.tagName == 'FORM') {
      arr["form"] = frm;
      var formElements = objForm.elements;
      for( var i=0; i < formElements.length; i++) {
        if (!formElements[i].name)
          continue;
        if (formElements[i].name.substring(0, prefix.length) != prefix)
          continue;
        if (formElements[i].type && (formElements[i].type == 'radio' || formElements[i].type == 'checkbox') && formElements[i].checked == false)
          continue;
        if (formElements[i].disabled && formElements[i].disabled == true && submitDisabledElements == false)
          continue;
        var name = formElements[i].name;
        if (name) {
          if(formElements[i].type=='select-multiple') {
            for (var j = 0; j < formElements[i].length; j++) {
              if (formElements[i].options[j].selected == true)
                arr[name] = this.encodeStr(formElements[i].options[j].value);
            }
          } else {
            arr[name] = this.encodeStr(formElements[i].value);
          }
        }
      }
    } else {
      this.parseChildren(objForm, zajax.getInputElements, arr);
    }
    return arr;
  }

  // Callback function which adds to an array the contents of all inputs within a dom node
  this.getInputElements = function(element, arr) {
    switch (element.type){
      case 'text':
      case 'password':
      case 'textarea':
      case 'hidden':
        arr[element.name] = zajax.encodeStr(element.value);
        break;
      case 'radio':
      case 'checkbox':
        if (element.checked == true)
    	    arr[element.name] = zajax.encodeStr(element.value);
        break;
      case 'select-one':
      case 'select-multiple':
        for ( val in element.options){
          if (element.options[val].selected == true)
            arr[element.name] = zajax.encodeStr(element.options[val].value);
        }
        break;
    }
    return true;
  }

  // Generates an XML message that zajax can understand from a javascript object
  this.objectToXML = function(obj) {
    var sXml = "<xjxobj>";
    for (i in obj) {
      try {
        if (i == 'constructor')
          continue;
        if (obj[i] && typeof(obj[i]) == 'function')
          continue;
        var key = i;
        var value = obj[i];
        if (value && typeof(value)=="object" && this.depth <= 50) {
          this.depth++;
          value = this.objectToXML(value);
          this.depth--;
        }
        sXml += "<e><k>"+key+"</k><v>"+value+"</v></e>";
      } catch(e) {
        this.debug(e);
      }
    }
    sXml += "</xjxobj>";
    return sXml;
  }

  //Get the XMLHttpRequest Object
  this.getRequestObject = function() {
    var req = null;
    if (typeof XMLHttpRequest != "undefined")
      req = new XMLHttpRequest();
    if (!req && typeof ActiveXObject != "undefined") {
      try {
        req=new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          req=new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e2) {
          try {
            req=new ActiveXObject("Msxml2.XMLHTTP.4.0");
          } catch (e3) {
            req=null;
          }
        }
      }
    }
    if(!req && window.createRequest)
      req = window.createRequest();
    if (!req)
      this.debug("Request Object Instantiation failed.");
    return req;
  }

    //Process XML zajaxResponses returned from the request
  this.processResponse = function(xml)
  {
    var tmpZajax = null;
    var skipCommands = 0;

    clearTimeout(loadingTimeout);
    this.doneLoadingFunction();

    xml = xml.documentElement;
		if (xml == null)
      return;

    for (var i=0; i<xml.childNodes.length; i++) {
      if (skipCommands > 0) {
        skipCommands--;
        continue;
      }
      if (xml.childNodes[i].nodeName == "cmd") {
        var cmd;
        var id;
        var property;
        var data;
        var search;
        var type;
        var before;
        var objElement = null;

        for (var j=0; j<xml.childNodes[i].attributes.length; j++) {
          switch (xml.childNodes[i].attributes[j].name){
            case "n":
              cmd = xml.childNodes[i].attributes[j].value;
              break;
            case "t":
              id = xml.childNodes[i].attributes[j].value;
              break;
            case "p":
              property = xml.childNodes[i].attributes[j].value;
              break;
            case "c":
              type = xml.childNodes[i].attributes[j].value;
          }
        }
        if (xml.childNodes[i].childNodes.length > 1 && xml.childNodes[i].firstChild.nodeName == "#cdata-section") {
          data = "";
          for (var j=0; j<xml.childNodes[i].childNodes.length; j++)
            data += xml.childNodes[i].childNodes[j].data;
        } else if (xml.childNodes[i].firstChild && xml.childNodes[i].firstChild.nodeName == 'xjxobj') {
          data = this._nodeToObject(xml.childNodes[i].firstChild);
          objElement = "XJX_SKIP";
        } else if (xml.childNodes[i].childNodes.length > 1) {
          for (var j=0; j<xml.childNodes[i].childNodes.length; j++) {
            var internalData = "";
            if (xml.childNodes[i].childNodes[j].childNodes.length > 1 && xml.childNodes[i].childNodes[j].firstChild.nodeName == "#cdata-section") {
              for (var k=0; k<xml.childNodes[i].childNodes[j].childNodes.length;k++)
                internalData+=xml.childNodes[i].childNodes[j].childNodes[k].nodeValue;
            } else {
              internalData = xml.childNodes[i].childNodes[j].firstChild.nodeValue;
            }

            if (xml.childNodes[i].childNodes[j].nodeName == "s")
              search = internalData;
            if (xml.childNodes[i].childNodes[j].nodeName == "r")
              data = internalData;
          }
        } else if (xml.childNodes[i].firstChild)
          data = xml.childNodes[i].firstChild.nodeValue;
        else
          data = "";

        if (objElement != "XJX_SKIP") objElement = this.$(id);
        var cmdFullname;
        try {
          switch (cmd) {
            case "cc":
              cmdFullname = "addConfirmCommands";
              var confirmResult = confirm(data);
              if (!confirmResult)
                skipCommands = id;
              break;
            case "al":
              cmdFullname = "addAlert";
              alert(data);
              break;
            case "js":
              cmdFullname = "addScript/addRedirect";
              eval(data);
              break;
            case "ls":
              cmdFullname = "addScriptWithTimeout";
              setTimeout(data,5000);
              break;
            case "jc":
              cmdFullname = "addScriptCall";
              var scr = id + '(';
              if (data[0] != null) {
                scr += 'data[0]';
                for (var l=1; l<data.length; l++)
                  scr += ',data['+l+']';
              }
              scr += ');';
              eval(scr);
              break;
            case "in":
              cmdFullname = "addIncludeScript";
              this.include(data);
              break;
            case "ic":
              cmdFullname = "addIncludeCss";
              this.includeCss(data);
              break;
            case "as":
              cmdFullname = "addAssign/addClear";
							if (data == "") {
								blend.initZajaxR(objElement,property,data);
								setTimeout('blend.doZajaxR()',blend.fadeTime);
								blend.opacity(id,blend.fadeOpac,blend.fadeTrsp,blend.fadeTime);
							} else {
								eval("objElement."+property+"=data;");
								blend.opacity(id,blend.fadeTrsp,blend.fadeOpac,blend.fadeTime);
							}
              break;
            case "ap":
              cmdFullname = "addAppend";
              eval("objElement."+property+"+=data;");
              break;
            case "pp":
              cmdFullname = "addPrepend";
              eval("objElement."+property+"=data+objElement."+property);
              break;
            case "rp":
              cmdFullname = "addReplace";
              this.replace(id,property,search,data);
              break;
            case "rm":
              cmdFullname = "addRemove";
              this.remove(id);
              break;
            case "ce":
              cmdFullname = "addCreate";
              this.create(id,data,property);
              break;
            case "ie":
              cmdFullname = "addInsert";
              this.insert(id,data,property);
              break;
            case "ia":
              cmdFullname = "addInsertAfter";
              this.insertAfter(id,data,property);
              break;
            case "ci":
              cmdFullname = "addCreateInput";
              this.createInput(id,type,data,property);
              break;
            case "ii":
              cmdFullname = "addInsertInput";
              this.insertInput(id,type,data,property);
              break;
            case "iia":
              cmdFullname = "addInsertInputAfter";
              this.insertInputAfter(id,type,data,property);
              break;
            case "ev":
              cmdFullname = "addEvent";
              property = this.addOnPrefix(property);
              eval("this.$('"+id+"')."+property+"= function(){"+data+";}");
              break;
            case "ah":
              cmdFullname = "addHandler";
              this.addHandler(id, property, data);
              break;
            case "rh":
              cmdFullname = "addRemoveHandler";
              this.removeHandler(id, property, data);
              break;
          }
        } catch(e) {
          this.debug("While trying to '" + cmdFullname +
                     "' (command number "+ i +
                     "), the following error occured:\n" + e.name +
                     ": " + e.message + "\n" +
                     (id && !objElement ? "Object with id='" + id + "' wasn't found.\n":""));
        }
        delete objElement;
        delete cmd;
        delete cmdFullname;
        delete id;
        delete property;
        delete search;
        delete data;
        delete type;
        delete before;
        delete internalData;
        delete j;
        delete k;
      }
    }
    delete xml;
    delete i;
  }

  // Main communication function with php
  this.call = function(sUri, sFunction, aArgs) {
    var i,r,postData,value;

    clearTimeout(loadingTimeout);
    loadingTimeout = setTimeout("zajax.loadingFunction();",0);

    if(sUri.indexOf('/') > -1) sUri = this.webPath + sUri;

    postData = "zajaxUri=" + this.encodeStr(sUri) + "&zajaxFcn=" + this.encodeStr(sFunction);
    if (aArgs){
      if (typeof(aArgs) == "object" || typeof(aArgs) == "array")
        postData += "&zajaxArgs="+this.encodeStr(this.objectToXML(aArgs));
      else if (aArgs[0] == '<') //<xjxqery> or similars from getFormValues
        postData += "&zajaxArgs="+this.encodeStr(aArgs);
      else {                    // this new option allows to make a direct call!
        alone = new Array();
        alone[0] = aArgs;
        postData += "&zajaxArgs="+this.encodeStr(this.objectToXML(alone));
      }
    }
    r = this.getRequestObject();
    if (!r)
      return false;
    r.open("POST", this.php, true);
    try {
      r.setRequestHeader("Method", "POST " + this.php + " HTTP/1.1");
      r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    } catch(e) {
      this.debug("Your browser does not appear to  support asynchronous requests using POST.");
      this.debug(e);
      return false;
    }
    r.onreadystatechange = function() {
      if (r.readyState != 4)
        return;
      if (r.status==200 && r.responseXML && r.responseXML.documentElement)
        zajax.processResponse(r.responseXML);
      else
        zajax.debug('Error receiving the response...')
      delete r;
      r = null;
    }
    r.send(postData);
    delete r;
    return true;
  }

  // this allows to
  this.wait = function(millis){
    date = new Date();
    curDate = null;
    do { curDate = new Date(); }
    while ( curDate-date < millis );
  }

  // Validates a form using the domains associated to the fields
  // number of parameters:
  // 0 : assumes the form id to be 'form'
  // 1 : receives a particular form id
  // 2 : receives the formid, and a javascript function that makes additional
  //     processing in case the validation succeeds
  // 3 : receives the formid, a path and a php function to make additional
  //     processing via zajax call in case the validation succeeds
  this.validate = function(formid){
    if (!formid || formid == "")
     formid = "form";
    args = new Array();
    switch (arguments.length){
      case 2:
        args['sJscriptFcn'] = arguments[1];
        break;
      case 3:
        args['sCallbackFile'] = (arguments[1].indexOf('/') > -1? this.webPath : '') + arguments[1];
        args['sCallbackFcn'] = arguments[2];
    }
    this.call('validate.php','zvalidateform',this.getFormValues(formid,args));
    return false;
  }

  // Each form element can be validated individually by using this function,
  // it can manage to execute a javascript function when succeeds and when it
  // fails.
  this.validatom = function(x,tval,fval){
    args = new Array();
    args[0] = x.id;
    args[1] = x.form.name;
    eval("args[2] = zajax.$('"+x.id+"').value");
    eval("dominios = zajax.$('d_"+x.id+"').value");
    closepar = 0;
    args[3] = '';
    openpar = dominios.indexOf('(');
    while (openpar != -1) {
      args[3] += dominios.substr(closepar,openpar-closepar+1);
      closepar = dominios.indexOf(')',openpar);
      strargs = dominios.substr(openpar+1,closepar-openpar-1);
      if(strargs.length > 0){
        arrargs = strargs.split(',');
        for ( val = 1 ; val < arrargs.length ; val++ )
        	args[3] += this.$(arrargs[val-1]).value.replace(':','[COLON]') + ',';
        args[3] += this.$(arrargs[val-1]).value.replace(':','[COLON]');
      }
      openpar = dominios.indexOf('(',closepar);
    }
    args[3] += dominios.substr(closepar);
    args[4]=tval;
    args[5]=fval;
    this.call('validate.php','zvalidatom',args);
  }

  /**
  * fcnNotificacion crea una notificacion usando zajax
  * sDonde es el div donde se va a ubicar el mensaje
  * sTipo es el grado de importancia y un icono:
  *    Alerta, Error, Informacion, Notificacion, Validacion
  * sMensaje cadena con el contenido del mensaje
  * sFocus es el input que recibirá el foco luego de la notificacion
  *    document.getElementById('$sFocus').focus();
  * sAncla es el ancla donde se ubicará el navegador luego de la notificación
  *    document.getElementById('$sAncla').focus();
  * por defecto es la cadena '#msg-notificacion'
  */
  this.showStatus = function(sDonde, sTipo, sMensaje, sFocus, sAncla, sAlineacion){
    args = new Array();
    for (idx = 0 ; idx < arguments.length; idx++)
      args[idx]=arguments[idx];
    blend.changeValues(1500, 99, 20);
    setTimeout('blend.changeValues(0, 99, 0)',1600); //para deshacer el blend
    this.call('validate.php','showStatus',args);
  }

  this.buttonsOriginal = new Array('Validar','Cancelar','Aceptar','Regresar');
  this.buttonsCaptions = this.buttonsOriginal;

  // Additional string to be evaluated after the success of the validation and
  // before the disabling of the form's elements.
  this.onValidated = function() { return(true); };

  // Function to be called when the left button of the forms is pressed the
  // first time.
  this.left1 = function(frm) {
    zajax.validate(frm,"if(zajax.onValidated(\""+frm+"\")){zajax.verifyForm(\""+frm+"\",false)}");
  }

  // Function to be called when the right button of the forms is pressed the
  // first time.
  this.right1 = function(frm) {
    this.$(frm).reset();
  }

  // Function to be called when the left button of the forms is pressed the
  // second time.
  this.left2 = function(frm) {
    this.onValidated = function() { return(true); };
    this.buttonsCaptions = this.buttonsOriginal;
    this.$(frm).submit();
  }

  // Function to be called when the right1 button of the forms is pressed the
  // second time.
  this.right2 = function(frm) {
    zajax.verifyForm(frm,true);
  }

  // This function is used by cefiro's formbuttons, it implements the two-step
  // validation-and-confirmation process of forms.
  this.verifyForm = function(frm, show){
    if (typeof(frm) == "string"){
      this.verifyElements('table_'+frm, show);
      left_btn = this.$('left_'+frm);
      right_btn = this.$('right_'+frm);
      if (show){
        left_btn.onclick = function() { zajax.left1(frm); };
        right_btn.onclick = function() { zajax.right1(frm); };
        left_btn.value = this.buttonsCaptions[0];
        right_btn.value = this.buttonsCaptions[1];
      } else {
        left_btn.onclick = function() { zajax.left2(frm); };
        right_btn.onclick = function() { zajax.right2(frm); };
        left_btn.value = this.buttonsCaptions[2];
        right_btn.value = this.buttonsCaptions[3];
      }
    }
  }

  // This is a wrapper function that shows how to use parseChildren with a
  // callback function to do some processing while traveling thorough the DOM
  // nodes, in this case activating/deactivating the form elements
  this.verifyElements = function(element, show) {
    if (typeof(element) == "string")
      objForm = this.$(element);
    else
      objForm = element;
    if (objForm)
      this.parseChildren(objForm, zajax.verifyElement, show)
  }

  // A very nice little recursive function, that travels thorough the DOM nodes,
  // executing a callback function
  this.parseChildren = function(node, fcn, args) {
    if (typeof(node) == "object"){
      fcn(node,args);
      if (node.childNodes && node.childNodes.length > 0)
        for ( idx in node.childNodes )
          this.parseChildren(node.childNodes[idx], fcn, args);
    }
  }

  // Callback function which turns on and off the elements of the form to allow
  // a final verification of the data to be submitted
  this.verifyElement = function(element, show) {
    if (element.tagName){
      switch (element.tagName){
        case 'IMG':
          if (show){
              element.width = element.widt_h;
              element.height = element.heigh_t;
          } else {
              element.widt_h = element.width;
              element.heigh_t = element.height;
              element.width = 0;
              element.height = 0;
          }
          break;
      }
    }
    if (element.type) {
      switch (element.type){
        case 'text':
          if (show){
            element.size = 20;
          } else {
            element.text = (String)(element.value);
            element.size = 0;
            element.selectionStart = 0;
            element.selectionEnd = 0;
            element.size = element.text.length;
            element.value = element.text;
          }
        case 'textarea':
          if (show){
            element.setAttribute('class',element.getAttribute('class_old'));
          } else {
            element.setAttribute('class_old',element.getAttribute('class'));
            element.setAttribute('class','input-lbl');
            if (element.type == 'textarea')
              element.innerHTML = element.value
          }
          break;
        case 'radio':
        case 'checkbox':
            if (show && element.childVisited) {
        	    element.removeAttribute('disabled');
        	    old_name = (element.id+'').slice(3);
        	    nBrother = zajax.document.getElementById(old_name);
              element.parentNode.removeChild(nBrother);
              element.id = old_name;
              element.name = old_name;
            } else if (!element.childVisited) {
              element.childVisited = true;
              element.setAttribute('disabled','true');
              nBrother = document.createElement('input');
              nBrother.setAttribute('type','hidden');
              nBrother.setAttribute('id',element.id);
              nBrother.setAttribute('name',element.id);
              if (element.checked)
                nBrother.setAttribute('value','true');
              element.id = 'chk'+element.id;
              element.parentNode.insertBefore(nBrother,element);
            }
          break;
        case 'select-one':
          if (show){
            text = zajax.$('n_'+element.id).value;
            for ( val in element.options){
              element.options[val].setAttribute('selected','false');
              if (element.options[val].text == text){
                element.options[val].setAttribute('selected','true');
                break;
              }
            }
            element.style.opacity = 1;
            element.style.width = element.old_width;
            element.parentNode.removeChild(zajax.$('n_'+element.id));
          } else if (!zajax.$('n_'+element.id)) {
            for ( val in element.options){
              if (element.options[val].selected == true){
                nBrother = document.createElement('input');
                nBrother.setAttribute('type','text');
                nBrother.setAttribute('id','n_'+element.id);
                nBrother.setAttribute('value',element.options[val].text);
                nBrother.setAttribute('class','input-lbl');
                nBrother.setAttribute('size',element.options[val].text.length);
                element.parentNode.insertBefore(nBrother,element);
              }
            }
            element.style.opacity = 0;
            element.old_width = element.style.width;
            element.style.width = 0;
          }
          break;
        case 'select-multiple':
          break;
      }
      if (show){
  	    element.removeAttribute('readonly');
        element.onfocus = element.onfocus_old;
        element.onclick = element.onclick_old;
        element.onblur = element.onblur_old;
        element.onselect = element.onselect_old;
      } else {
        element.setAttribute('readonly','true');
        element.onfocus_old = element.onfocus;
        element.onfocus = null;
        element.onclick_old = element.onclick;
        element.onclick = null;
        element.onblur_old = element.onblur;
        element.onblur = null;
        element.onselect_old = element.onselect;
        element.onselect = null;
      }
    return true;
    }
  }

}

var zajax = new Zajax();
var blend = new Blend();
// Aun no ha sido integrada esta funcionalidad
//zajax.include(zajax.zUri + 'validate.js');
zajax.webPath = '../../../sigelab/web/';